/**
 * Created by dale on 2017/10/19.
 */
/**
 * Created by dale on 2017/10/19.
 */
var noticemsgList;
var startDom;
var endDom;
$(document).ready(function () {
    noticemsgList = $('#noticeMsgList');
    $('.xh-datagrid-toolbar').parseToolbar();

    startDom = $('#List_Search_StartTime');
    endDom = $('#List_Search_EndTime');
    startDom.datebox();
    endDom.datebox();

    noticemsgList.initDataGrid(baseUrl + 'short/manage/getNoAflist', {queryParams: getParams()}).setSelectThenEnable(['bt_list_del']);

    xhTool.bindDocKeyDown($('#bt_list_search'));
    $('#bt_list_search').click(function () {
        noticemsgList.addDataGridParams(getParams());
    });
    DataGrid.onDblClickRow = function (rowIndex, rowData) {
        var iNoId = rowData['iId'];
        window.top.xhTop.showModal({
            title: rowData['sName'],
            content: '<iframe src="' + baseUrl + 'short/manage/add?id=' + iNoId + '"  style="width: 100%;;border-style: none;padding: 0px;height:520px"  scrolling="yes"   ></iframe>',
            button: '提交',
            backClose: false,
            width: 970
        });
        return false;
    }
});
$('#bt_list_add').click(function () {
    window.top.xhTop.showModal({
        title: '新增权限',
        content: '<iframe src="' + baseUrl + 'short/manage/add"  style="width: 100%;;border-style: none;padding: 0px;height:500px"  scrolling="yes"   ></iframe>',
        button: '提交',
        backClose: false,
        width: 970
    });
});

$('#bt_list_del').click(function () {
    var ids = noticemsgList.getDataGridSelectedFields('iId');
    var sTag = noticemsgList.getDataGridSelectedFields('sTag');

    if (noticemsgList.getDataGridSelectedFields('iId').length > 0) {
        window.top.swal({
            title: "确定要删除数据吗,用户勾选的快捷键也将一并删除,请谨慎操作？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定！",
            cancelButtonText: "取消",
            closeOnConfirm: false,
            closeOnCancel: false
        }).then(function (isConfirm) {
            xhExtra.ajaxRequest('short/manage/delShort', {ids: ids,sTag:sTag}, {}, function (res) {
                window.top.swal(
                    '操作成功',
                    '',
                    'success'
                );
                noticemsgList.datagrid('reload');
            })
        });

    }
    else {
        window.top.swal('错误,请选择需要移除的数据', '', 'error');
        return false;
    }
});

function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1;//获取当前月份的日期
    var d = dd.getDate();
    return y + "-" + m + "-" + d;
}

function getParams() {
    var key = xhExtra.getValue($('#list_search'));
    var model = $("#model").find("option:selected").text();
    var type = xhExtra.getValue($('#select_type'));
    var params = {key: key, model: model, type: type};
    return params;
}